package com.poizon.infrastructure.center.config.core.value.dto;


import java.util.Collections;
import java.util.Map;
import java.util.Set;

public class ConfigChangeEventDto {
    private final String m_namespace;
    private final Map<String, ConfigChangeDto> m_changes;

    /**
     * Constructor.
     *
     * @param namespace the namespace of this change
     * @param changes   the actual changes
     */
    public ConfigChangeEventDto(String namespace, Map<String, ConfigChangeDto> changes) {
        this.m_namespace = namespace;
        this.m_changes = changes;
    }

    /**
     * Get the keys changed.
     *
     * @return the list of the keys
     */
    public Set<String> changedKeys() {
        return m_changes.keySet();
    }

    /**
     * Maybe subclass override this method.
     *
     * @return interested and changed keys
     */
    public Set<String> interestedChangedKeys() {
        return Collections.emptySet();
    }

    /**
     * Get a specific change instance for the key specified.
     *
     * @param key the changed key
     * @return the change instance
     */
    public ConfigChangeDto getChange(String key) {
        return m_changes.get(key);
    }

    /**
     * Check whether the specified key is changed
     *
     * @param key the key
     * @return true if the key is changed, false otherwise.
     */
    public boolean isChanged(String key) {
        return m_changes.containsKey(key);
    }

    /**
     * Get the namespace of this change event.
     *
     * @return the namespace
     */
    public String getNamespace() {
        return m_namespace;
    }
}
